package com.ds.dsm.view.config.form.field.group;

import com.ds.common.JDSException;
import com.ds.config.ResultModel;
import com.ds.dsm.view.config.form.field.FieldButtonView;
import com.ds.dsm.view.config.form.service.FormFieldService;
import com.ds.esd.custom.annotation.FormViewAnnotation;
import com.ds.esd.custom.api.annotation.APIEventAnnotation;
import com.ds.esd.custom.bean.CustomView;
import com.ds.esd.custom.bean.MethodConfig;
import com.ds.esd.custom.form.enums.CustomFormMenu;
import com.ds.esd.custom.module.annotation.ModuleAnnotation;
import com.ds.esd.custom.nav.annotation.NavGroupAnnotation;
import com.ds.esd.custom.toolbar.BottomBarMenu;
import com.ds.esd.dsm.DSMFactory;
import com.ds.esd.dsm.view.ViewEntityConfig;
import com.ds.esd.dsm.view.field.FieldFormConfig;
import com.ds.esd.tool.ui.enums.Dock;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/dsm/view/config/form/filed/")
@BottomBarMenu
@NavGroupAnnotation(
        bottombarMenu = {CustomFormMenu.Save, CustomFormMenu.ReSet}, customService = FormFieldService.class)
public class FieldButtonGroup extends FieldLabelBaseGroup {
    public FieldButtonGroup() {
    }



    @RequestMapping(method = RequestMethod.POST, value = "FieldBottonInfo")
    @FormViewAnnotation
    @ModuleAnnotation( imageClass = "xui-icon-dialog", caption = "视频", dock = Dock.top, height = "380")
    @APIEventAnnotation(autoRun = true)
    @ResponseBody
    public ResultModel<FieldButtonView> getFieldBottonInfo(String sourceClassName, String sourceMethodName, String fieldname,String domainId, String viewInstId) {
        ResultModel<FieldButtonView> result = new ResultModel<FieldButtonView>();
        try {
            ViewEntityConfig classConfig = DSMFactory.getInstance().getViewManager().getViewEntityConfig(sourceClassName,viewInstId);
            MethodConfig customMethodAPIBean = classConfig.getSourceConfig().getMethodByName(sourceMethodName);
            CustomView viewBean = customMethodAPIBean.getView();
            FieldFormConfig formInfo = (FieldFormConfig) viewBean.getFieldByName(fieldname);
            formInfo.setEntityClassName(viewBean.getEntityClassName());
            result.setData(new FieldButtonView(formInfo));
        } catch (JDSException e) {
            e.printStackTrace();
        }
        return result;
    }


}
